# Complete project details at https://RandomNerdTutorials.com
import time
from umqttsimple import MQTTClient
import ubinascii
import machine
import micropython
import network
import esp
from machine import Pin
esp.osdebug(None)
import gc
gc.collect()

ssid = 'Mi 10'
password = '88888888'
#EXAMPLE IP ADDRESS
mqtt_server = '192.168.119.92'

client_id = ubinascii.hexlify(machine.unique_id())
topic_sub = b'ledctl'
topic_pub = ''

# 上次发送消息的时间
last_message = 0
# 每条消息发送之间的时间间隔(秒)
message_interval = 5
# 添加到消息中的计数器
counter = 0
def do_connect():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        wlan.connect(ssid, password)
        i = 1
        while not wlan.isconnected():
            print("正在链接...{}".format(i))
            i += 1
            time.sleep(1)
    print('Connection wifi successful')
    print('network config:', wlan.ifconfig())
do_connect()
